package com.jianglin.state2.controller;

import com.jianglin.state2.core.ResponsePack;
import com.jianglin.state2.dao.entity.WageInfo;
import com.jianglin.state2.model.params.WageInfoAddParams;
import com.jianglin.state2.model.params.WageInfoUpdateParams;
import com.jianglin.state2.service.WageInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@ResponsePack
@RequestMapping("/wageInfo")
@Api(tags = {"员工工资信息"})
public class WageInfoController {
    private final WageInfoService wageInfoService;

    @Autowired
    public WageInfoController(WageInfoService wageInfoService ) {
        this.wageInfoService = wageInfoService;
    }

    @GetMapping("/all")
    @ApiOperation("获得所有员工工资信息")
    public List<WageInfo> getAll() {
        return wageInfoService.list();
    }

    @PostMapping("/add")
    @ApiOperation("添加员工工资信息")
    public boolean saveWageInfo(@Validated @RequestBody WageInfoAddParams wageInfoAddParams){
        WageInfo wageInfo = wageInfoAddParams.convertOut();
        return wageInfoService.save(wageInfo);
    }

    @PutMapping("/{id}")
    @ApiOperation("更新员工工资信息")
    public boolean updateWageInfo(@ApiParam("信息编号") @PathVariable Integer id,
                                  @Validated @RequestBody WageInfoUpdateParams wageInfoUpdateParams){
        WageInfo wageInfo = wageInfoUpdateParams.convertOut();
        wageInfo.setWageInfoId(id);
        return wageInfoService.updateById(wageInfo);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除员工工资信息")
    public boolean deleteWageInfo(@ApiParam("信息编号") @PathVariable String id) {
        return wageInfoService.removeById(id);
    }
}